<template>
  <el-dialog title="抢单记录" class="order-member-dialog" :visible.sync="visible" :close-on-click-modal="false" :before-close="handleCloseDialog"

    width="1200px">
    <div class="app-container">
      <el-card class="filter-container" shadow="never">
        <div>
          <el-button style="float:right" type="primary" @click="handleSearchList()" size="mini">
            查询搜索
          </el-button>
          <el-button style="float:right;margin-right: 15px" @click="handleResetSearch()" size="mini">
            重置
          </el-button>
        </div>
        <div>
          <el-form :inline="true" :model="listQuery" size="mini" label-width="100px">
            <el-form-item label="订单号：">
              <el-input v-model="listQuery.orderNo" class="input-width" placeholder="请输入手机号码" clearable></el-input>
            </el-form-item>
            <el-form-item label="订单状态：">
              <el-select v-model="listQuery.state" class="input-width" placeholder="请选择订单状态">
                <el-option v-for="item in stateOptions" :key="item.code" :label="item.desc" :value="item.code">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="下单时间：">
              <el-date-picker v-model="listQuery.date" type="daterange" range-separator="至" clearable
                start-placeholder="开始日期" end-placeholder="结束日期">
              </el-date-picker>
            </el-form-item>

          </el-form>
        </div>
      </el-card>
      <div class="table-container order-member-container">
        <el-table ref="adminTable" size="mini" :data="list" style="width: 100%;" v-loading="listLoading" border>
          <el-table-column label="订单号" width="180" align="center">
            <template slot-scope="scope">{{ scope.row.orderNo }}</template>
          </el-table-column>
          <el-table-column label="昵称" width="120" align="center">
            <template slot-scope="scope">{{ scope.row.nickname }}</template>
          </el-table-column>
          <el-table-column label="手机号" width="120" align="center">
            <template slot-scope="scope">{{ scope.row.phoneNo }}</template>
          </el-table-column>
          <el-table-column label="广告图片" align="center">
            <template slot-scope="scope">
              <div v-viewer class="img-box">
                <img :src="scope.row.goodsPic ? `${user.filePreviewUrl}/${scope.row.goodsPic}` : ''">
              </div>
            </template>
          </el-table-column>
          <el-table-column label="广告名称"  width="120" align="center">
            <template slot-scope="scope">{{ scope.row.goodsName }}</template>
          </el-table-column>
          <el-table-column label="最低投入" align="center">
            <template slot-scope="scope">{{ formatAmount(scope.row.minPrice) }}</template>
          </el-table-column>
          <el-table-column label="最高投入" align="center">
            <template slot-scope="scope">{{ formatAmount(scope.row.maxPrice) }}</template>
          </el-table-column>
          <el-table-column label="交易金额" align="center">
            <template slot-scope="scope">{{ formatAmount(scope.row.orderAmount) }}</template>
          </el-table-column>
          <el-table-column label="佣金" width="80" align="center">
            <template slot-scope="scope">{{ formatAmount(scope.row.rebateAmount) }}</template>
          </el-table-column>
          <el-table-column label="下单时间" width="160" align="center">
            <template slot-scope="scope">{{ scope.row.createTime | formatDateTime }}</template>
          </el-table-column>
          <el-table-column label="解冻时间" width="160" align="center">
            <template slot-scope="scope">{{ scope.row.createTime | formatDateTime }}</template>
          </el-table-column>
          <el-table-column label="交易状态" align="center">
            <template slot-scope="scope">{{ stateObj[scope.row.state] }}</template>
          </el-table-column>
        </el-table>
      </div>
      <div class="pagination-container">
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
          layout="total, sizes,prev, pager, next,jumper" :current-page.sync="listQuery.pageNum"
          :page-size="listQuery.pageSize" :page-sizes="[5, 10, 15, 20]" :total="total">
        </el-pagination>
      </div>

    </div>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="handleConfirmDialog('adminForm')" size="mini" :loading="loading">确 定</el-button>
      <el-button @click="handleCloseDialog" size="mini">取 消</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { getStorage,formatAmount} from "@/utils/index";
import { formatDate } from '@/utils/date';
import { getOrderList } from '@/api/transaction';
const defaultListQuery = {
  pageNum: 1,
  pageSize: 10,
  orderNo: null,
  state: '',
  date:[]
};
export default {
  data() {
    return {
      listQuery: Object.assign({}, defaultListQuery),
      list: null,
      total: null,
      listLoading: false,
      stateOptions:[{desc: '全部', code: ''}],
      user: getStorage('user') || {},
      stateObj:{},
      visible: true,

    };
  },
  props: {
    row: {
      type: Object,
      default: {}
    }
  },
  created() {
    this.stateOptions=[...this.stateOptions,...getStorage('commonEnums').orderInfoStateEnum];
    this.stateOptions.forEach(item=>{this.stateObj[item.code]=item.desc})
    this.getList();
  },
  filters: {
    formatDateTime(time) {
      if (time == null || time === '') {
        return 'N/A';
      }
      let date = new Date(time);
      return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
    }
  },
  methods: {
     formatAmount,
    handleCloseDialog() {
      this.$emit("handle-cancel");
    },
    handleConfirmDialog(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.loading = true;

          updateMemberInfo({ ...this.dataObject, id: this.row.id }).then(response => {
            this.resetForm(formName);
            this.$message({
              message: "提交成功",
              type: "success",
              duration: 1000
            });
            this.loading = false;
            this.$emit("handle-confirm");
          }).catch(() => {
            this.loading = false;
          });
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.dataObject = Object.assign({}, defaultObject);
    },
    handleResetSearch() {
      this.listQuery = Object.assign({}, defaultListQuery);
      this.getList();
    },
    handleSearchList() {
      this.listQuery.pageNum = 1;
      this.getList();
    },
    handleSizeChange(val) {
      this.listQuery.pageNum = 1;
      this.listQuery.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.pageNum = val;
      this.getList();
    },
   
    getList() {
      this.listLoading = true;
      let params = {...this.listQuery,memberId:this.row.id};
      if(params.date&&params.date.length>0){
        params.startTime = formatDate(params.date[0],"yyyy-MM-dd hh:mm:ss");
        params.endTime = formatDate(params.date[1],"yyyy-MM-dd hh:mm:ss");
      }
       delete params.date;
      if (params.state==='') delete params.state;
     
      getOrderList(params).then(response => {
        this.listLoading = false;
        this.list = response.data.list;
        this.total = response.data.total;
      });
    }
  }
};
</script>
<style scoped>
.img-box {
  img {
    width: 50px;
    height: 50px;
    border: solid 1px #eee;
    cursor: pointer;
  }
}
.input-width{
  width: 140px;
}
</style>

<style lang="scss">
.order-member-container{
  height: calc(100vh - 510px);
  .el-table__body-wrapper{
    height: calc(100vh - 560px);
    overflow-y: auto;
  }
}
.order-member-dialog{
  .el-dialog__body{
    height: 60vh!important;
    overflow: hidden;
  }
}

</style>